class cutPage{
    constructor(objs){
        this.data=objs.data;
        this.pageLength=objs.pageLength;
        this.list=document.getElementById("list");
        this.select1=document.getElementById("select1");
        this.maxpage=Math.ceil(this.data.length/this.pageLength[0]);//默认页码
        this.pagenum=1;//初始页
        this.page=document.querySelector(".page");
        this.nexts=document.querySelector(".nexts");
        this.prevs=document.querySelector(".prevs");
        this.init(this.data,this.pageLength,objs,this.maxpage);
    }
    init(data,pageLength,objs,maxpage){
        objs.cb3(pageLength);
        this.limit=this.select1.value;//默认显示多少条数据
        this.filterPage(maxpage);
        this.renderData();
        this.bindEvent();
    }
    filterPage(maxpage){//渲染初始页码
        let html="";
        for(let i=0;i<maxpage;i++){
            html+=`<li>${i+1}</li>`
        }
        this.list.innerHTML=html;
        this.list.firstChild.style.background="orange";
    }
    renderData(){//渲染页面
        this.start=this.limit*(this.pagenum-1);
        this.end=this.limit*this.pagenum;
       
        this.tit=this.data.slice(this.start,this.end);
        let str="";
        this.tit.map((item)=>{
            str+=`<li>第<b style="color:red">${item}</b>章节</li>`
        }).join("");
        this.page.innerHTML=str;
    }
    bindEvent(){//各种事件
        this.select1.onchange=(()=>{//点击select
            this.limit=this.select1.value;
            this.maxpage=Math.ceil(this.data.length/this.limit);
            this.pagenum=1;
            this.filterPage(this.maxpage);
            this.renderData();
        })
        //点击下一页
        this.nexts.onclick=(()=>{
            if(this.pagenum<this.maxpage){
                this.pagenum++;
                this.renderData();
            }
        })
        //点击下一页
        this.prevs.onclick=(()=>{
           if(this.pagenum>1){
               this.pagenum--;
               this.renderData();
           }
        })
        //点击li
        this.list.onclick=((e)=>{
            this.pagenum=e.target.innerHTML;
            console.log(this.pagenum);
            this.renderData();
        })
    }
}